import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from 'vue-router'
import Bus from "@/utils/eventBus";
const routes: Array<RouteRecordRaw> = [

    // 首页
    {
        path: "/homepage",
        name: 'homepage',
        component: () => import("@/views/homepage.vue"),
    },

    {
        path: "/",
        name: 'home',
        redirect: '/cockpit/index',
        component: () => import("@/views/home/index.vue"),
        children: [
            /* 后台设置 */
            {
                path: "/set/camera",
                name: 'set_camera',
                meta: {
                    name: '摄像头设置'
                },
                component: () => import("@/views/home/set/camera.vue"),
            },
            {
                path: "/set/patrol",
                name: 'set_patrol',
                meta: {
                    name: '设备配置'
                },
                component: () => import("@/views/home/set/patrol.vue"),
            },
            {
                path: "/set/patrol",
                name: 'set_patrol_account',
                meta: {
                    name: '账号配置'
                },
                component: () => import("@/views/home/set/patrol_account.vue"),
            },
            {
                path: "/set/department",
                name: 'set_department',
                meta: {
                    name: '部门设置'
                },
                component: () => import("@/views/home/set/department.vue"),
            },

            {
                path: "/set/user",
                name: 'set_user',
                meta: {
                    name: '人员设置'
                },
                component: () => import("@/views/home/set/user.vue"),
            },
            {
                path: "/set/account",
                name: 'set_account',
                meta: {
                    name: '账号设置'
                },
                component: () => import("@/views/home/set/account.vue"),
            },
            /* 仪表盘 */
            {
                path: "/cockpit/index",
                name: 'cockpit_index',
                meta: {
                    name: '驾驶舱'
                },
                component: () => import("@/views/home/cockpit/index.vue"),
            },
            /* 模具 */
            {
                path: "/mould/index",
                name: 'mould_index',
                meta: {
                    name: '模具管理'
                },
                component: () => import("@/views/home/mould/index.vue"),
            },
            /* 预警 */
            {
                path: "/warning/index",
                name: 'warning_index',
                meta: {
                    name: '预警统计'
                },
                component: () => import("@/views/home/warning/warning.vue"),
            },
            {
                path: "/warning/visual",
                name: 'warning_visual',
                meta: {
                    name: '实时预警可视化'
                },
                component: () => import("@/views/home/warning/warning_visual.vue"),
            },
            {
                path: "/warning/calculation",
                name: 'warning_calculation',
                meta: {
                    name: '边缘计算盒管理'
                },
                component: () => import("@/views/home/warning/calculation.vue"),
            },
            /* 视频汇聚 */
            {
                path: "/video/index",
                name: 'video_index',
                meta: {
                    name: '摄像头配置'
                },
                component: () => import("@/views/home/video/video.vue"),
            },
            {
                path: "/video/visual",
                name: 'video_visual',
                meta: {
                    name: '视频可视化'
                },
                component: () => import("@/views/home/video/video_visual.vue"),
            },
            {
                path: "/video/overview",
                name: 'video_overview',
                meta: {
                    name: '视频概览'
                },
                component: () => import("@/views/home/video/video_overview.vue"),
            },
            {
                path: "/video/videoiframe",
                name: 'video_videoiframe',
                meta: {
                    name: '流媒体配置'
                },
                component: () => import("@/views/home/video/videoiframe.vue"),
            },
            /* 巡检 */
            {
                path: "/inspection/idnex",
                name: 'inspection_index',
                meta: {
                    name: '智能巡检'
                },
                component: () => import("@/views/home/inspection/index.vue"),
            },
            {
                path: "/inspection/artificial",
                name: 'inspection_artificial',
                meta: {
                    name: '人工巡检'
                },
                component: () => import("@/views/home/inspection/artificial.vue"),
            },
            {
                path: "/inspection/idnex",
                name: 'inspection_overview',
                meta: {
                    name: '巡检概览'
                },
                component: () => import("@/views/home/inspection/overview.vue"),
            },
            {
                path: "/inspection/patrolLog",
                name:"inspection_patrolLog",
                meta:{
                    name:"巡检日志"
                },
                component: ()=> import("@/views/home/inspection/patrolLog.vue")
            },
            {
                path: "/inspection/list",
                name:"inspection_list",
                meta:{
                    name:"巡检日志"
                },
                component: ()=> import("@/views/home/inspection/list.vue")
            },
            {
                path: "/repair/index",
                name: 'repair_index',
                meta: {
                    name: '设备概览'
                },
                component: () => import("@/views/home/repair/index.vue"),
            },
            {
                path: "/repair/repairs",
                name: 'repair_repairs',
                meta: {
                    name: '设备报修'
                },
                component: () => import("@/views/home/repair/repairs.vue"),
            },
            /* 应急 */
            {
                path: "/emergency/index",
                name: 'emergency_index',
                meta: {
                    name: '应急演练'
                },
                component: () => import("@/views/home/emergency/index.vue"),
            },
            // 智能票据
            {
                path: "/bill/index",
                name: 'bill_index',
                meta: {
                    name: '应急演练'
                },
                component: () => import("@/views/home/bill/index.vue"),
            },
            {
                path: "/bill/dialogtest",
                name: 'bill_dialogtest',
                meta: {
                    name: '应急演练'
                },
                component: () => import("@/views/home/bill/dialogtest.vue"),
            },
            {
                path: "/emergency/group",
                name: 'emergency_group',
                meta: {
                    name: '应急组配置'
                },
                component: () => import(/* webpackChunkName: "emergency_group" */ "@/views/home/emergency/group.vue"),
            },
            {
                path: "/emergency/plan",
                name: 'emergency_plan',
                meta: {
                    name: '应急预案配置'
                },
                component: () => import("@/views/home/emergency/plan.vue"),
            },


            /* 能耗检测 */
            {
                path: "/energy/index",
                name: 'energy_index',
                meta: {
                    name: '水表数据概括'
                },
                component: () => import("@/views/home/energy/index.vue"),
            },

            /* 环境检测 */
            {
                path: "/environment/index",
                name: 'environment_index',
                meta: {
                    name: '环境数据概括'
                },
                component: () => import("@/views/home/environment/index.vue"),
            },
            {
                path: "/environment/dust",
                name: 'environment_dust',
                meta: {
                    name: '扬尘检测设备'
                },
                component: () => import("@/views/home/environment/dust.vue"),
            },
            {
                path: "/environment/spray",
                name: 'environment_spray',
                meta: {
                    name: '喷淋联动设备'
                },
                component: () => import("@/views/home/environment/spray.vue"),
            },

            /* 智能安全帽 */
            {
                path: "/safetyhat/index",
                name: 'safetyhat_index',
                meta: {
                    name: '安全帽分布'
                },
                component: () => import("@/views/home/safetyhat/index.vue"),
            },
            {
                path: "/safetyhat/list",
                name: 'safetyhat_list',
                meta: {
                    name: '安全帽列表'
                },
                component: () => import("@/views/home/safetyhat/list.vue"),
            },


            /* 智能安全帽 */
            {
                path: "/enclosure/index",
                name: 'enclosure_index',
                meta: {
                    name: '安全帽分布'
                },
                component: () => import("@/views/home/enclosure/index.vue"),
            },

            /* AI开放 */
            {
                path: "/aicome/index",
                name: 'aicome_index',
                meta: {
                    name: '自助演示'
                },
                component: () => import("@/views/home/aicome/index.vue"),
            },
            {
                path: "/aicome/exhibition",
                name: 'aicome_exhibition',
                meta: {
                    name: '场景展示'
                },
                component: () => import("@/views/home/aicome/exhibition.vue"),
            },
            {
                path: "/aicome/platform",
                name: 'aicome_platform',
                meta: {
                    name: '开放平台'
                },
                component: () => import("@/views/home/aicome/platform.vue"),
            },

            /* 空页面 */
            {
                path: "/dashboard/null",
                name: 'dashboard_null',
                meta: {
                    name: '仪表板空1'
                },
                component: () => import("@/views/home/dashboard/null.vue"),
            },
            {
                path: "/dashboard/null2",
                name: 'dashboard_null2',
                meta: {
                    name: '仪表板空2'
                },
                component: () => import("@/views/home/dashboard/null.vue"),
            },
        ]
    },
    {
        path: "/h5/emergency/:id",
        name: 'h5_emergency',
        component: () => import("@/views/h5/emergency/index.vue")
    },
    {
        path: "/login",
        name: 'login',
        component: () => import("@/views/login.vue")
    },
]


const router = createRouter({
    history: createWebHashHistory(),
    routes
})

// 全局守卫：登录拦截 本地没有存token,请重新登录
router.beforeEach((to, from, next) => {
    if (to.meta.name) {
        Bus.$emit('change-router', {
            title: to.meta.name,
            router: to.name
        })
    }
    next();
});


export default router